{extend name="normal_base" /}
{block name="navigation"}{/block}
{block name="css"}
{/block}
{block name="body"}
<div class="x-body">
    <div class="layui-form-item">
        <label for="contract-number-view" class="layui-form-label">
            合同编号：
        </label>
        <div class="layui-input-inline">
            <input type="text" id="contract-number-view"  name="" value="{$contract_number}" disabled autocomplete="off" class="layui-input">
        </div>
    </div>

    <!--合同扫描件-->
    <div class="layui-form-item">
        <label for="take_back_user" class="layui-form-label">
            扫描件：
        </label>
        <div class="layui-input-inline">
            <button type="button" class="layui-btn layui-btn-normal" id="scanning_file_id">
                <i class="layui-icon">&#xe67c;</i>点击上传合同扫描件&nbsp;&nbsp;
            </button>
            <!--<div class="layui-upload-drag" id="test10">
                <i class="layui-icon"></i>
                <p>点击上传，或将文件拖拽到此处</p>
            </div>-->
        </div>
        <div class="layui-form-mid layui-word-aux">
            <span id="show-is-upload">仅支持pdf格式</span>
        </div>
    </div>

    <form class="layui-form" id="from_id" method="POST" action="{:url('recycle')}">
        <!--项目分组-->
        <div class="layui-form-item">
            <label class="layui-form-label">项目组：</label>
            <div class="layui-input-inline">
                <select name="project_group_id" id="project_group_id" lay-filter="sign_company_code">
                    <option value=''>请选择</option>
                    {foreach name='project_group_list' item='v' key="k"}
                    <option value="{$k}" {if condition="$k==$project_group_id"}selected="selected"{/if}>{$v}</option>
                    {/foreach}
                </select>
            </div>
        </div>

        <!--回收时间-->
        <div class="layui-form-item">
            <label for="take_back_time" class="layui-form-label">
                <span class="x-red">*</span>&nbsp;回收时间</i>：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="take_back_time" name="take_back_time" placeholder="请选择..." value="" required lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--回收人-->
        <div class="layui-form-item">
            <label for="take_back_user" class="layui-form-label">
                <span class="x-red">*</span>&nbsp;回收人员</i>：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="take_back_user" name="take_back_user" placeholder="" value="" lay-verify="required|m_input_short"
                       autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="hidden" name="id" value="{$id}">
                <input type="hidden" id="scanning_file_url" name="scanning_file" value="">
                <button  class="layui-btn" lay-filter="recyle" lay-submit="">
                    回收
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>
</div>
{/block}

{block name="script"}

<script>
    layui.use(['form','layer','laydate', 'upload'], function(){
        $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form
        var laydate = layui.laydate;
        var upload = layui.upload;

        //自定义验证规则
        form.verify({
            m_input_short:function (value) {
                //验证长度是否超出限制,50个字
                if (value != "") {
                    if(value.length > 10){
                        return '内容长度超出限制，最多 10 个字';
                    }
                }
            }
        });

        //执行一个laydate实例- 年度选择
        laydate.render({
            elem: '#take_back_time' //指定元素
            ,type: 'datetime'
            ,theme: 'molv' //主题：default（默认简约）、molv（墨绿背景）、#颜色值（自定义颜色背景）、grid（格子主题）
        });

        /*文件上传*/
        var uploadInst = upload.render({
            elem: '#scanning_file_id'
            ,url: '{:url("upload_scanning")}'
            ,acceptMime:'application/pdf'
            ,exts:'pdf'
            ,field:'file[]'
            ,data:{
                contract_number:function () {
                    return $('#contract-number-view').val();
                }
            }
            ,accept: 'file' //允许上传的文件类型
            ,size: 10*1024*1024 //最大允许上传的文件大小
            ,before: function(obj){ //obj参数包含的信息，跟 choose回调完全一致，可参见上文。
                $('#show-is-upload').text('上传中，请等待...');
                layer.load(); //上传loading
            }
            ,done: function(data){
                //上传完毕回调
                if (data.code == 1) {
                    layer.msg(data.msg,{icon:5,time:1500});
                } else {
                    //上传成功
                    layer.closeAll('loading'); //关闭loading
                    $('#scanning_file_url').val(data.msg);
                    $('#show-is-upload').text('已上传');
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('上传扫描件失败！');
            }
        });

        //监听提交
        form.on('submit(recyle)', function(data){
            $("#from_id").ajaxSubmit({
                beforeSubmit:function () {
                    //表单提交前
                },
                success:function (data) {
                    //console.log(JSON.stringify(data));
                    if (data.code == 1) {
                        layer.msg(data.msg,{icon:5,time:1500});
                    } else {
                        layer.alert("回收成功", {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            //刷新父层页面
                            parent.location.replace(parent.location.href);
                        });
                    }
                }
            });
            return false;
        });
    });


</script>
{/block}